/*
 * @Descripttion: 患者预约医师，创建一条预约记录
 * @version: 1.0
 * @Author: 自由如风
 * @Date: 2021-05-04 21:46:37
 * @LastEditors: 自由如风
 * @LastEditTime: 2021-05-05 09:28:51
 */
const DB = require("../../lib/DB")
const { Success, Fail } = require("../../lib/Response")

module.exports = async function (ctx, nect) {
    try {
        const { id } = (await DB.models.foresee.create({
            time: ctx.request.body.time,
            memo: ctx.request.body.memo,
            doctor_id: ctx.request.body.doctor_id,
            patient_id: ctx.session.patient.id,
            state: '等待处理',
        })).toJSON();
        const foresee = await DB.models.foresee.findOne({
            where: { id }, include: [
                {
                    model: DB.models.user,
                    as: 'doctor',
                }, {
                    model: DB.models.patient,
                    as: 'patient'
                }
            ]
        })
        ctx.body = new Success(foresee.toJSON())
    } catch (e) {
        ctx.body = new Fail(e.message)
    }
}